// package com.xuyuan.ai.auto;
//
// import io.micrometer.observation.ObservationRegistry;
// import org.springframework.ai.autoconfigure.vectorstore.redis.RedisVectorStoreProperties;
// import org.springframework.ai.embedding.BatchingStrategy;
// import org.springframework.ai.embedding.EmbeddingModel;
// import org.springframework.ai.embedding.TokenCountBatchingStrategy;
// import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
// import org.springframework.ai.vectorstore.redis.RedisVectorStore;
// import org.springframework.beans.factory.ObjectProvider;
// import org.springframework.beans.factory.annotation.Qualifier;
// import org.springframework.boot.autoconfigure.AutoConfiguration;
// import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
// import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
// import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
// import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
// import org.springframework.boot.context.properties.EnableConfigurationProperties;
// import org.springframework.context.annotation.Bean;
// import org.springframework.context.annotation.Configuration;
// import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
// import redis.clients.jedis.DefaultJedisClientConfig;
// import redis.clients.jedis.HostAndPort;
// import redis.clients.jedis.JedisClientConfig;
// import redis.clients.jedis.JedisPooled;
//
// /**
//  * 适配多种大模型,重写RedisVectorStoreAutoConfiguration
//  *
//  * @see org.springframework.ai.autoconfigure.vectorstore.redis.RedisVectorStoreAutoConfiguration
//  */
// @Configuration
// @AutoConfiguration(after = RedisAutoConfiguration.class)
// @ConditionalOnClass({JedisPooled.class, JedisConnectionFactory.class, RedisVectorStore.class, EmbeddingModel.class})
// @ConditionalOnBean({JedisConnectionFactory.class})
// @EnableConfigurationProperties({RedisVectorStoreProperties.class})
// public class RedisVectorStoreAutoConfiguration {
//     public RedisVectorStoreAutoConfiguration() {
//     }
//
//     @Bean
//     @ConditionalOnMissingBean({BatchingStrategy.class})
//     BatchingStrategy batchingStrategy() {
//         return new TokenCountBatchingStrategy();
//     }
//
//     @Bean("redisVectorStore")
//     public RedisVectorStore vectorStore(@Qualifier("qianFanEmbeddingModel") EmbeddingModel embeddingModel, RedisVectorStoreProperties properties, JedisConnectionFactory jedisConnectionFactory, ObjectProvider<ObservationRegistry> observationRegistry, ObjectProvider<VectorStoreObservationConvention> customObservationConvention, BatchingStrategy batchingStrategy) {
//         return RedisVectorStore.builder(this.jedisPooled(jedisConnectionFactory), embeddingModel)
//                 .initializeSchema(properties.isInitializeSchema())
//                 .observationRegistry(observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP))
//                 .customObservationConvention(customObservationConvention.getIfAvailable(() -> null))
//                 .batchingStrategy(batchingStrategy)
//                 .indexName(properties.getIndex())
//                 .prefix(properties.getPrefix())
//                 .build();
//     }
//
//     private JedisPooled jedisPooled(JedisConnectionFactory jedisConnectionFactory) {
//         String host = jedisConnectionFactory.getHostName();
//         int port = jedisConnectionFactory.getPort();
//         JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().ssl(jedisConnectionFactory.isUseSsl()).clientName(jedisConnectionFactory.getClientName()).timeoutMillis(jedisConnectionFactory.getTimeout()).password(jedisConnectionFactory.getPassword()).build();
//         return new JedisPooled(new HostAndPort(host, port), clientConfig);
//     }
// }
